package communication;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;


public class Communication {
	
	public ObjectOutputStream out;
	public ObjectInputStream in;
	public Socket socket;
	
	public Communication(Socket socket) throws IOException
	{
		this.socket = socket;
		out = new ObjectOutputStream(socket.getOutputStream());
		out.flush();
		in = new ObjectInputStream(socket.getInputStream());
	}
	
	public void sendMessage(String message) throws IOException
	{
		out.writeObject(message);
		out.flush();
	}
	
	public String getMessage() throws IOException, ClassNotFoundException
	{
		return (String)in.readObject();
	}
	
	public void close() throws IOException
	{
		in.close();
		out.close();
		socket.close();
	}

}
